﻿using System;
using Zove.Runtime.Core;

namespace Zove.Runtime.Test {
    public static class AssertableZoveObject {

        public static void Assert(this IQueryable queryObject, params string[] assertions)
        {
            ZoveObject zoveObject = (ZoveObject) queryObject;

            foreach (string assertion in assertions)
            {
                string key = assertion.Split('=')[0].Trim();
                RuntimeFactor factor = zoveObject.Model.Factors[key];

                string expression = assertion.Split('=')[1].Trim();
                object value = zoveObject.Evaluate(expression);
                double result = Convert.ToDouble(value);

                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(factor.Status == RuntimeFactorStatus.Input || factor.Status == RuntimeFactorStatus.Solved, "The factor " + factor.Name + " is not solved yet.");
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(result, factor.Value);
            }
        }
    }
}
